package data;

import java.util.Date;

import com.EntityName;
import com.Util;
import com.google.appengine.api.datastore.Entity;

public class HouseKeeping extends AbstractData{
	private long id = -1;
	private long hotelId;
	private long roomId;
	private String reference;
	private User staff;
	private String staffString;
	private Date statusdate;
	public String getReference() {
		return reference;
	}
	public void setReference(String reference) {
		this.reference = reference;
	}
	public User getStaff() {
		if (staff == null && !(staffString == null || staffString.isEmpty())) {
			User s = new User(Long.parseLong(staffString));
			s.LoadData();
			staff = s;
		}
		return staff;
	}
	public void setStaff(User staff) {
		this.staffString = String.format("%d", staff.getId());
		this.staff = staff;
	}
	public void setStaffId(long staffId){
		this.staffString = Long.toString(staffId);
		if(staffId == -1)
			this.staffString = "";
	}
	public String getStaffId(){
		return this.staffString;
	}
	public Date getStatusdate() {
		return statusdate;
	}
	public void setStatusdate(Date statusdate) {
		this.statusdate = Util.GetOnlyDate(statusdate);
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public long getHotelId() {
		return hotelId;
	}
	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}
	public long getRoomId() {
		return roomId;
	}
	public void setRoomId(long roomId) {
		this.roomId = roomId;
	}
	public Entity getEntity()
	{
		Entity item;
		
		if(this.key == null)
			item = new Entity(EntityName.HouseKeeping);
		else
			item = new Entity(this.key);

		item.setProperty("hotelId", this.hotelId);
		item.setProperty("roomId", this.roomId);
		item.setProperty("reference", this.reference);
		item.setProperty("userId", this.staffString);
		item.setProperty("statusdate", this.statusdate);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.roomId = (Long) entity.getProperty("roomId");
		this.reference = (String) entity.getProperty("reference");
		this.staffString= (String) entity.getProperty("userId");
		this.statusdate =(Date) entity.getProperty("statusdate");
		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.HouseKeeping, this.id);
			setEntity(entity);
		}
	}
}
